<?php
/**
* 
* @param undefined $string
* @param undefined $tamanho
* @param undefined $encode
* 
*/
function limitar($str, $limite) {
        $strfinal="";
        $i = "";
        $str = strip_tags($str);
        $tamanhodotexto=strlen(strval($str));
        if ($tamanhodotexto <= $limite) { /// CONTROLA SE O LIMITE É MAIOR QUE A STRING
                        $strfinal = $str . " ";
                return 	
                        $strfinal;
        }
        else{		
                for ($i = 0; $i <= strlen($str); $i++) { 
                        if ($i > $limite) {
                                        if ($i == strlen($str) || $str[$i]==' ' || $str[$i]==',' || $str[$i]=='.' ) {
                                                $strfinal .= " ...";
                                                return $strfinal;
                                        }
                                        $strfinal .= $str[$i];
                        }
                        else {
                                if ($i <= strlen($str)-1)
                                        $strfinal .= $str[$i];
                        }
                }
        }
        return $strfinal;
}


function dateConvert($date, $format = "l d F Y") {
        $months = array("january" => "Janeiro", "february" => "Fevereiro", "march" => "Março", "april" => "Abril", "may" => "Maio", "june" => "Junho", "july" => "Julho", "august" => "Agosto", "september" => "Setembro", "october" => "Outubro", "november" => "Novembro",
            "december" => "Dezembro");
        $weeks = array("sunday" => "Domingo", "monday" => "Segunda-Feira", "tuesday" => "Terça-Feira", "wednesday" => "Quarta-Feira", "thursday" => "Quinta-Feira", "friday" => "Sexta-Feira", "saturday" => "Sábado");
        $months3 = array("jan" => "jan", "feb" => "fev", "mar" => "mar", "apr" => "abr", "may" => "mai", "jun" => "jun", "jul" => "jul", "aug" => "ago", "sep" => "set", "oct" => "out", "nov" => "nov", "dec" => "dez");
        $weeks3 = array("sun" => "dom", "mon" => "seg", "tue" => "ter", "wed" => "qua", "thu" => "qui", "fri" => "sex", "sat" => "sab");

        $date = strtolower(date($format, strtotime($date)));
        $date = strtr($date, $months);
        $date = strtr($date, $weeks);
        $date = strtr($date, $months3);
        $date = strtr($date, $weeks3);
        return $date;
    }
?>